﻿using BigEgg.Framework.Foundation;
using BigEgg.Framework.UnitTesting;
using FMStudio.Documents.TemplateDocument.Models;
using FMStudio.Documents.TemplateDocument.Properties;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml.Linq;

namespace FMStudio.Documents.TemplateDocument.Test.Models
{
    [TestClass]
    public class TemplateWizardTest
    {
        [TestMethod]
        public void PropertiesWithNotification()
        {
            TemplateWizard wizard = new TemplateWizard();

            AssertHelper.PropertyChangedEvent(wizard, x => x.Assembly, () => wizard.Assembly = "SomeAssebly");
            Assert.AreEqual("SomeAssebly", wizard.Assembly);

            AssertHelper.PropertyChangedEvent(wizard, x => x.FullClassName, () => wizard.FullClassName = "SomeClass");
            Assert.AreEqual("SomeClass", wizard.FullClassName);
        }

        [TestMethod]
        public void AssemblyValidationTest()
        {
            TemplateWizard wizard = new TemplateWizard();

            Assert.AreEqual("", wizard.Assembly);
            Assert.AreEqual(Resources.TemplateWizardAssemblyMandatory, wizard.Validate("Assembly"));

            wizard.Assembly = "SomeAssebly";
            Assert.AreEqual("SomeAssebly", wizard.Assembly);
            Assert.AreEqual("", wizard.Validate("Assembly"));
        }

        [TestMethod]
        public void FullClassNameValidationTest()
        {
            TemplateWizard wizard = new TemplateWizard();

            Assert.AreEqual("", wizard.FullClassName);
            Assert.AreEqual(Resources.TemplateWizardFullClassNameMandatory, wizard.Validate("FullClassName"));

            wizard.FullClassName = "SomeClass";
            Assert.AreEqual("SomeClass", wizard.FullClassName);
            Assert.AreEqual("", wizard.Validate("FullClassName"));
        }

        [TestMethod]
        public void SerializationTest()
        {
            TemplateWizard wizard = new TemplateWizard();

            XElement element = wizard.ObjectToXElement();
            Assert.IsNotNull(element.Element("Assembly"));
            Assert.IsNotNull(element.Element("FullClassName"));
            TemplateWizard newWizard = element.XElementToObject<TemplateWizard>();
        }
    }
}
